<?php
/**
 * @package Google Safe Browsing
 * @version 1.0
 */
/*
Plugin Name: Google Safe Browsing Report
Plugin URI: https://code.google.com/p/wp-google-safe-browsing-dashboard/
Description: Fetches the Google Safe Browsing Report for the current domain and displays it in the dashboard.
Author: Joe Kovar III
Version: 1.0
Author URI: http://www.develobert.info
*/

// Create the function to output the contents of our Dashboard Widget
function google_safe_browsing_report()
{
	$url = @network_home_url();
	if(!empty($url))
	{
		$host = @parse_url($url, PHP_URL_HOST);
		if(!empty($host))
		{
			$report = @wp_remote_fopen("http://google.com/safebrowsing/diagnostic?site={$host}");
			if(!empty($report))
			{
				if(preg_match_all('#<blockquote>(.+)</blockquote>#Ui', $report, $u))
				{
					unset($report);
					echo str_replace('<a href="', '<a target="_blank" href="http://google.com', implode($u[1]));
				}
				else
				{
					echo '<p>', __('Unexpected response from Google'), '</p>';
				}
			}
			else
			{
				echo '<p>', __('Unable to fetch Google Safe Browsing Report'), '</p>';
			}
		}
		else
		{
			echo '<p>', __('Unable to parse returned network home'), '</p>';
		}
	}
	else
	{
		echo '<p>', __('Unable to determine current network home'), '</p>';
	}
}

// Create the function use in the action hook
function google_safe_browsing_report_setup()
{
	wp_add_dashboard_widget('google_safe_browsing_report', 'Google Safe Browsing Report', 'google_safe_browsing_report');	
} 
// Hook into the 'wp_dashboard_setup' action to register our other functions
add_action('wp_dashboard_setup', 'google_safe_browsing_report_setup');

?>
